//
//  ZH_MallViewModel.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/11/6.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_MallViewModel.h"
//删除收货地址
#define orderDel_address       @"/api/order/del_address"
//积分产品获取
#define goodsScore_goods       @"/api/goods/score_goods"
//提交订单页面收货人信息请求
#define orderAddress_detail    @"/api/order/address_detail"
//评价回复接口
#define goodsComment_reply     @"/api/goods/comment_reply"
//加入购物车
#define goodsInsert_shop_car   @"/api/goods/insert_shop_car"
//订单页面请求接口
#define goodsBuy               @"/api/goods/buy"
//商品评论列表
#define goodsReplay_list       @"/api/goods/replay_list"
//修改收货人信息
#define orderChange_address    @"/api/order/change_address"
//设置默认收货地址
#define orderSet_selected      @"/api/order/set_selected"
//购物车数量修改
#define goodsChange_num        @"/api/goods/change_num"
//购物车列表
#define goodsShop_car          @"/api/goods/shop_car"
//修改设置页面QQ/微信信息
#define bind_third             @"/api/personal/bind_third"
@implementation ZH_MallViewModel
//删除收货地址
- (void)delAddressResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:orderDel_address dictionaryParam:self.delAddressParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//积分产品获取
- (void)scoreGoodsResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsScore_goods dictionaryParam:self.scoreGoodsParam withResultBlock:^(NSString *code, NSString *message, id data) {
        
    }];
}

//提交订单页面收货人信息请求
- (void)detailResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:orderAddress_detail dictionaryParam:self.detailParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//评价回复接口
- (void)replyResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsComment_reply dictionaryParam:self.replyParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//加入购物车
- (void)shopCarResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsInsert_shop_car dictionaryParam:self.shopCarParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//订单页面请求接口
- (void)goodsBuyResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsBuy dictionaryParam:self.goodsBuyParam withResultBlock:^(NSString *code, NSString *message, id data) {
        
    }];
}

//商品评论列表
- (void)goodsListResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsReplay_list dictionaryParam:self.goodsListParam withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"];
        }
        if(resultArray.count > 0){
            [self.goodsListArray removeAllObjects];
            [self.goodsListArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }
    }];
}

//修改收货人信息
- (void)changeAddressResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:orderChange_address dictionaryParam:self.changeAddressParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//设置默认收货地址
- (void)selectedAddressResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:orderSet_selected dictionaryParam:self.selectedAddressParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//购物车数量修改
- (void)changeNumResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsChange_num dictionaryParam:self.changNumParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//购物车列表
- (void)shopCarListResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:goodsShop_car dictionaryParam:self.shopCarListParam withResultBlock:^(NSString *code, NSString *message, id data) {
        
    }];
}

//修改设置页面QQ/微信信息
- (void)modifyResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:bind_third dictionaryParam:self.modifyParam withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}
#pragma mark - getter,setter
//删除收货地址
- (NSMutableDictionary *)delAddressParam{
    if (!_delAddressParam) {
        _delAddressParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_delAddressParam setObject:@"" forKey:@"token"];
        [_delAddressParam setObject:@"" forKey:@"id"];
    }
    return _delAddressParam;
}

//积分产品获取
- (NSMutableDictionary *)scoreGoodsParam{
    if (!_scoreGoodsParam) {
        _scoreGoodsParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_scoreGoodsParam setObject:@"" forKey:@"token"];
    }
    return _scoreGoodsParam;
}
- (NSMutableArray *)scoreGoodsArray{
    if (!_scoreGoodsArray) {
        _scoreGoodsArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _scoreGoodsArray;
}

//提交订单页面收货人信息请求
- (NSMutableDictionary *)detailParam{
    if (!_detailParam) {
        _detailParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_detailParam setObject:@"" forKey:@"token"];
    }
    return _detailParam;
}
//评价回复接口
- (NSMutableDictionary *)replyParam{
    if (!_replyParam) {
        _replyParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_replyParam setObject:@"" forKey:@"token"];
        [_replyParam setObject:@"" forKey:@"id"];
        [_replyParam setObject:@"" forKey:@"content"];
    }
    return _replyParam;
}
//加入购物车
- (NSMutableDictionary *)shopCarParam{
    if (!_shopCarParam) {
        _shopCarParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_shopCarParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_shopCarParam setObject:@"1" forKey:@"num"];
        [_shopCarParam setObject:@"" forKey:@"id"];
    }
    return _shopCarParam;
}

//订单页面请求接口
- (NSMutableDictionary *)goodsBuyParam{
    if (!_goodsBuyParam) {
        _goodsBuyParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_goodsBuyParam setObject:@"" forKey:@"token"];
        [_goodsBuyParam setObject:@"" forKey:@"id"];
        [_goodsBuyParam setObject:@"" forKey:@"num"];
        [_goodsBuyParam setObject:@"" forKey:@"type"];
        [_goodsBuyParam setObject:@"" forKey:@"shop_car_id"];
    }
    return _goodsBuyParam;
}
- (NSMutableArray *)goodsBuyArray{
    if (!_goodsBuyArray) {
        _goodsBuyArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _goodsBuyArray;
}

//商品评论列表
- (NSMutableDictionary *)goodsListParam{
    if (!_goodsListParam) {
        _goodsListParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_goodsListParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_goodsListParam setObject:@"" forKey:@"id"];
        [_goodsListParam setObject:@"" forKey:@"score"];
    }
    return _goodsListParam;
}
- (NSMutableArray *)goodsListArray{
    if (!_goodsListArray) {
        _goodsListArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _goodsListArray;
}

//修改收货人信息
- (NSMutableDictionary *)changeAddressParam{
    if (!_changeAddressParam) {
        _changeAddressParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_changeAddressParam setObject:@"" forKey:@"token"];
        [_changeAddressParam setObject:@"" forKey:@"id"];
        [_changeAddressParam setObject:@"" forKey:@"phone"];
        [_changeAddressParam setObject:@"" forKey:@"name"];
        [_changeAddressParam setObject:@"" forKey:@"province"];
        [_changeAddressParam setObject:@"" forKey:@"city"];
        [_changeAddressParam setObject:@"" forKey:@"address"];
        [_changeAddressParam setObject:@"" forKey:@"area"];
    }
    return _changeAddressParam;
}
//设置默认收货地址
- (NSMutableDictionary *)selectedAddressParam{
    if (!_selectedAddressParam) {
        _selectedAddressParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_selectedAddressParam setObject:@"" forKey:@"token"];
        [_selectedAddressParam setObject:@"" forKey:@"id"];
    }
    return _selectedAddressParam;
}
//购物车数量修改
- (NSMutableDictionary *)changNumParam{
    if (!_changNumParam) {
        _changNumParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_changNumParam setObject:@"" forKey:@"token"];
        [_changNumParam setObject:@"" forKey:@"id"];
        [_changNumParam setObject:@"" forKey:@"type"];
    }
    return _changNumParam;
}

//购物车列表
- (NSMutableDictionary *)shopCarListParam{
    if (!_shopCarListParam) {
        _shopCarListParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_shopCarListParam setObject:@"" forKey:@"token"];
    }
    return _shopCarListParam;
}
- (NSMutableArray *)shopCarListArray{
    if (!_shopCarListArray) {
        _shopCarListArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _shopCarListArray;
}
//修改设置页面QQ/微信信息
- (NSMutableDictionary *)modifyParam{
    if (!_modifyParam) {
        _modifyParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_modifyParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_modifyParam setObject:@"" forKey:@"type"];
        [_modifyParam setObject:@"" forKey:@"data"];
    }
    return _modifyParam;
}
@end
